package com.sky.service.impl;

import com.sky.service.FileUploadService;
import com.sky.utils.AliOssUtil;
import com.sky.utils.CosUtil;
import com.sky.utils.PathUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;

@Service
public class FileUploadServiceImpl implements FileUploadService {

    @Autowired
    private CosUtil cosUtil;

    @Override
    public String upload(MultipartFile multipartFile) throws IOException {
        String path = PathUtils.generateFilePath(multipartFile.getOriginalFilename());
        HashMap map = cosUtil.uploadPublicFile(multipartFile, path);
        String  url = (String) map.get("url");
        return url;
    }
}
